﻿using FTBS.Models.DAO;
using FTBS.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FTBS.Models.BLO
{
    public class RoleBLO
    {
        private RoleDAO _roleDAO = new RoleDAO();

        /// <summary>
        /// List all roles in LoadRoles at RoleDAO
        /// </summary>
        /// <returns>role list</returns>
        /// <author>duyhdv</author>
        /// <date>2014/03/3</date>
        public List<Role> LoadAllRoles()
        {
            var roleList = _roleDAO.LoadRoles();
            return roleList;
        }

        /// <summary>
        /// Load role by Id 
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns>A current role</returns>
        /// <author>duyhdv</author>
        /// <date>2014/03/3</date>
        public Role LoadARole(int roleId)
        {
            var curRole = _roleDAO.SelectRole(roleId);
            return curRole;
        }

        /// <summary>
        /// Check if role is existed or not
        /// </summary>
        /// <param name="rol"></param>
        /// <returns>true || false</returns>
        /// <author>duyhdv</author>
        /// <date>2014/03/3</date>
        public bool CheckIsExisted(Role role)
        {
            return _roleDAO.CheckIsExisted(role);
        }

        /// <summary>
        /// Create a new role
        /// </summary>
        /// <param name="role"></param>
        /// <returns>true || false</returns>
        /// <author>duyhdv</author>
        /// <date>2014/03/3</date>
        public bool AddRole(Role role)
        {
            if (_roleDAO.Add(role) == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// get role id by role name
        /// </summary>
        /// <param name="roleName"></param>
        /// <returns>roleId</returns>
        /// <author>hungph</author>
        public int GetRoleIdByName(String roleName)
        {
            return _roleDAO.GetRoleIdByName(roleName);
        }

        /// <summary>
        /// Update a role
        /// </summary>
        /// <param name="role"></param>
        /// <returns>true || false</returns>
        /// <author>duyhdv</author>
        /// <date>2014/03/3</date>
        public bool UpdateRole(Role role)
        {
            var isUpdated = _roleDAO.Edit(role);
            if (isUpdated == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Delete a role
        /// </summary>
        /// <param name="role"></param>
        /// <returns> true || false</returns>
        /// <author>duyhdv</author>
        /// <date>2014/03/3</date>
        public bool DeleteRole(Role role)
        {
            var isDeleted = _roleDAO.Delete(role);
            //if Delete in roleDAO sucessfull
            if (isDeleted == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        internal object AddRole()
        {
            throw new NotImplementedException();
        }
    }
}